package cn.dlc.com.config.response;

import cn.dlc.com.system.user.entity.UserEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @Author: dlc
 * @Date: 2021/8/2 - 15:19
 * 通用响应
 */
@ApiModel("响应信息")
public class ResponseVO<T> implements Serializable {

    @ApiModelProperty(value="响应编码",position = 0)
    private int code;

    @ApiModelProperty(value="响应信息", position = 1)
    private String msg;

    @ApiModelProperty(value="响应数据" ,position = 2)
    private T data;

    @ApiModelProperty(value="响应时间戳", position = 3)
    private long timestamp;

    public ResponseVO(){

    }

    public ResponseVO(int code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    public ResponseVO(ResponseHttpStatus status, T data){
        this.code = status.getCode();
        this.msg = status.getMsg();
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    /**
     * 错误信息
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static <T> ResponseVO<T> error(int code, String msg, T data){
        return new ResponseVO<T>(code, msg, data);
    }


    /**
     * 错误信息
     * @param msg
     * @param data
     * @return
     */
    public static <T> ResponseVO<T> error500(String msg, T data){
        return new ResponseVO<>(500, msg, data);
    }

    /**
     * 错误信息
     * @param data
     * @return
     */
    public static <T> ResponseVO<T> error(T data){
        return new ResponseVO<>(
                ResponseHttpStatus.REQUEST_ERROR,data);
    }

    /**
     *
     * @param status
     * @param data
     * @return
     */
    public static <T> ResponseVO<T> error(ResponseHttpStatus status, T data) {
        return  new ResponseVO<>(status, data);
    }

    /**
     *
     * @param status
     * @return
     */
    public static <T> ResponseVO<T> error(ResponseHttpStatus status) {
        return new ResponseVO<>(status, null);
    }

    // 请求成功==============分割线=============================================================================
    // 请求成功==============分割线=============================================================================


    /**
     * 请求成功
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static <T> ResponseVO<T> success(int code, String msg, T data){
        return new ResponseVO<T>(code, msg, data);
    }

    /**
     * 请求成功
     * @param msg
     * @param data
     * @return
     */
    public static <T> ResponseVO<T> success(String msg, T data){
        return new ResponseVO<>(200, msg, data);
    }

    /**
     * 请求成功
     * @param data
     * @return
     */
    public static <T> ResponseVO<T> success(T data){
        return new ResponseVO<>(
                ResponseHttpStatus.REQUEST_SUCCESS,
                data);
    }

    /**
     *
     * @param status ResponseHttpStatus枚举类型
     * @param data 响应数据
     * @return
     */
    public static <T> ResponseVO<T> success(ResponseHttpStatus status, T data) {
        return new ResponseVO<>(status, data);
    }

    /**
     *
     * @param status ResponseHttpStatus枚举类型
     * @return
     */
    public static <T> ResponseVO<T> success(ResponseHttpStatus status) {
        return  new ResponseVO<>(status, null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public String toString() {
        return "ResponseVO{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
